﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using An_Im.Extension.Contract;
using An_Im.Properties;
using Microsoft.Office.Tools.Ribbon;
using PPT = Microsoft.Office.Interop.PowerPoint;

namespace An_Im.Command
{
    /// <summary>
    /// 全局命令管理器。
    /// </summary>
    static partial class CommandManager
    {

        /// <summary>
        /// 命令组列表。
        /// </summary>
        public static IList<CommandGroup> CommandGroupList { get; private set; }
        
        /// <summary>
        /// 默认命令组。
        /// </summary>
        public static CommandGroup DefaultCommandGroup => _defaultGroup;
        private static CommandGroup _defaultGroup = null;


        /// <summary>
        /// 手动初始化。
        /// </summary>
        public static void Initialize()
        {
            var list = new List<CommandGroup>();
            var mainGroup = new CommandGroup("An\'Im");
            mainGroup.AddVBAExportableCommand("以图形整理动画", "以图形对象进行动画排序。", null, SortSequenceByShape, VBACode.以图形对象进行动画排序);
            mainGroup.AddVBAExportableCommand("以类型整理动画", "以类型对象进行动画排序。", null, SortSequenceByType, VBACode.以图形对象进行动画排序);
            mainGroup.AddVBAExportableCommand("快捷触发器", "为图形建立快捷触发器。", null, CreateQuickTrigger, VBACode.建立快捷触发器);
            mainGroup.AddVBAExportableCommand("摆正图形", "重新设置图形的选框。", null, ResetShapeSelectionFrame, VBACode.摆正图形);
            mainGroup.AddVBAExportableCommand("文字矢量化", "将文本框中文本拆分为零散矢量图形。", null, TextBoxTransfer, VBACode.文字矢量化);
            mainGroup.AddVBAExportableCommand("动画预览", "特别感谢：@只为设计。预览动画。", null, AnimationPreview, VBACode.动画预览);

            _defaultGroup = mainGroup;
            list.Add(mainGroup);
            CommandGroupList = list;
        }

        public static void LoadExtend()
        {
            foreach (var extend in CoreManipulator.ExtensionHost.Extensions)
            {
                foreach (var cmd in extend.CustomCommandList)
                {
                    cmd.AddIn = extend;
                    _defaultGroup.Add(cmd.Name, cmd);
                }
                extend.Initialize(CoreManipulator.App, TaskPaneManager.CustomTaskPaneCollection);
            }
            
        }

        public static IAnImCommand GetCommand(string name)
        {
            foreach (var commandGroup in CommandGroupList)
            {
                if (commandGroup.ContainsKey(name)) return commandGroup[name];
            }
            return null;
        }


    }
}

